package com.example.demo5.info.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo5.info.mapper.UserMapper;
import com.example.demo5.info.pojo.User;
import com.example.demo5.result.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/test")
    public String aaa(){
        return "hhhhh";
    }
    /**
     * 查询  用mybatisplus
     * @return
     */
    @GetMapping("/list")
    public AjaxResult findAll(){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();//这是固定的东西
        List<User> users = userMapper.selectList(queryWrapper);//这是查使用上面的东西去查找所有的数据等于users
        queryWrapper.eq("age",26);//查找age ==26的值
        List<User> users1 = userMapper.selectList(queryWrapper);
        queryWrapper.like("name","南");
        List<User> users2 = userMapper.selectList(queryWrapper);
        System.out.println(users2);
        return AjaxResult.success(users2);
    }
}
